package com.amigo.online.provider.adv.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import com.amigo.online.common.param.common.KeyValueModel;

@Mapper
public interface AdvRecommendStockMapper {

    @Update({" <script> "
            + " <foreach item='temp' collection = 'updateObject' open='' close='' separator = ';'>"
            + " update adv_recommend_stock_tbl set remaining_number = "
            + " <if test = '#{temp.value} !=null'> #{temp.value}</if>"
            + " <if test = '#{temp.value} ==null'> remaining_number </if>"
            + " where adv_id = #{temp.id}"
            + " </foreach>"
            + " </script>"
    })
    void storageAdvRestNumberFromRedis(@Param("updateObject") List<KeyValueModel<Long, Integer>> updateObjectList);

    @Update("update adv_home_stock_tbl set over_used_number = over_used_number + 1 where adv_id = #{id}")
    void recordOverUsedNumber(@Param("id") Long advId);

    @Update("update adv_home_stock_tbl set click_number = click_number + 1 where adv_id = #{id}")
    void recordClickNumber(@Param("id") Long advId);

}
